<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul {
            display: flex;
            list-style: none;
        }

        li {
            margin: 10px 20px;
        }
    </style>
</head>

<body>
    <!-- s使用hash模式原理 -->
    <ul>
        <li>
            <a href="#/home">首页</a>
        </li>
        <li>
            <a href="#/category">分类</a>
        </li>
        <li>
            <a href="#/car">购物车</a>
        </li>
        <li>
            <a href="#/mine">我的</a>
        </li>
    </ul>

    <router-view id="box"></router-view>
</body>

</html>
<script>
    let box = document.querySelector('#box')
    // 使用hashchange 事件监听hash值的改变
    window.onhashchange = () => {
        console.log(location);
        if (location.hash == '#/home') {
            box.innerHTML = '首页'
        }
        if (location.hash == '#/category') {
            box.innerHTML = '分类'
        }
        if (location.hash == '#/car') {
            box.innerHTML = '购物车'
        }
        if (location.hash == '#/mine') {
            box.innerHTML = '我的'
        }
    }


</script>